package cn.biplam.common.paramters;

import cn.biplam.common.wrapper.ErrorMessage;

/**
 * 模型类型索引
 * @author XiaoRuxing 2009-6-27下午07:39:19
 * @version 1.0
 */
public class ModelType {

	/** 源系统模型 */
	public static final String Src = "1";
	/** 业务对象模型 */
	public static final String Bm = "2";
	/** 数据仓库模型 */
	public static final String Dw = "3";
	/** 基础指标模型 */
	public static final String Bdsl = "4";
	/** 数据集市模型 */
	public static final String Dm = "5";
	
	/**
	 * 业务模型类型 
	 */
	public enum Model_Type{
		/** 源系统模型 */
		Src ("1"),
		/** 业务对象模型 */
		Bm ("2"),
		/** 数据仓库模型 */
		Dw ("3"),
		/** 基础指标模型 */
		Bdsl ("4"),
		/** 数据集市模型 */
		Dm ("5");
		private String value;
		private Model_Type(String value){this.value=value;}
		public String toString() {return value;}
	}
	
	/**
	 * 业务模型对象元素类型 
	 */
	public enum Model_Object_Type{
		/** 根主题 */
		ROOT("1"),
		/** 非根主题 */
		NON_ROOT("2"),
		/** 表 */
		TABLE("3");
		
		private String value;
		private Model_Object_Type(String value){this.value=value;}
		public String toString() {return value;}
	}
	
	/**
	 * 业务模型对象类型名称
	 * @param objectType 对象类型代码
	 */
	public static String getModelObjectTypeName(String objectType){
		if(Model_Object_Type.ROOT.toString().equals(objectType)){
			return "根主题";
		}else if(Model_Object_Type.NON_ROOT.toString().equals(objectType)){
			return "非根主题";
		}else if(Model_Object_Type.TABLE.toString().equals(objectType)){
			return "表";
		}else{
			return null;
		}
	}
	
	/**
	 * 根据对象的类型，取对象的枚举类型
	 * @param modelType
	 * @return	Model_Type
	 * @throws ErrorMessage
	 */
	public static Model_Type getModelType(String modelType) throws ErrorMessage{
		if(ModelType.Src.toString().equals(modelType)){
			return Model_Type.Src;
		}else if(ModelType.Bm.toString().equals(modelType)){
			return Model_Type.Bm;
		}else if(ModelType.Dw.toString().equals(modelType)){
			return Model_Type.Dw;
		}else if(ModelType.Bdsl.toString().equals(modelType)){
			return Model_Type.Bdsl;
		}else if(ModelType.Dm.toString().equals(modelType)){
			return Model_Type.Dm;
		}else{
			throw new ErrorMessage("ModelType is not found("+modelType+")");
		}
	}
	
	/**
	 * 依据模型类型，返回业务模型表的字段MD存储表名称
	 * @param modelType
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String getColumnTableName(Model_Type modelType) throws ErrorMessage{
		String tableName;
		switch(modelType){
		case Src:
			tableName="SRC_MODEL_TABLE_COL";
			break;
		case Bm:
			tableName="BM_MODEL_TABLE_COL";
			break;
		case Dw:
			tableName="DW_MODEL_TABLE_COL";
			break;
		case Bdsl:
			tableName="BDSL_MODEL_TABLE_COL";
			break;
		case Dm:
			tableName="DM_MODEL_TABLE_COL";
			break;
		default:
			throw new ErrorMessage("未处理的模型类型("+modelType+")");
		}
		return tableName;
	}
	
	/**
	 * 依据模型类型，返回业务模型表的存储表名称
	 * @param modelType
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String getTableName(Model_Type modelType) throws ErrorMessage{
		String tableName;
		switch(modelType){
		case Src:
			tableName="SRC_MODEL_TABLE";
			break;
		case Bm:
			tableName="BM_MODEL_TABLE";
			break;
		case Dw:
			tableName="DW_MODEL_TABLE";
			break;
		case Bdsl:
			tableName="BDSL_MODEL_TABLE";
			break;
		case Dm:
			tableName="DM_MODEL_TABLE";
			break;
		default:
			throw new ErrorMessage("未处理的模型类型("+modelType+")");
		}
		return tableName;
	}
	
	/**
	 * 依据模型类型，返回业务模型外键的存储表名称
	 * @param modelType
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String getFkTableName(Model_Type modelType) throws ErrorMessage{
		String tableName;
		switch(modelType){
		case Src:
			tableName="SRC_TABLE_FOREIGN_REF";
			break;
		case Bm:
			tableName="BM_TABLE_FOREIGN_REF";
			break;
		case Dw:
			tableName="DW_TABLE_FOREIGN_REF";
			break;
		case Bdsl:
			tableName="BDSL__TABLE_FOREIGN_REF";
			break;
		case Dm:
			tableName="DM__TABLE_FOREIGN_REF";
			break;
		default:
			throw new ErrorMessage("未处理的模型类型("+modelType+")");
		}
		return tableName;
	}

	/**
	 * 依据模型类型，返回业务模型外键字段的存储表名称
	 * @param modelType
	 * @return	String
	 * @throws ErrorMessage
	 */
	public static String getFkColumnTableName(Model_Type modelType) throws ErrorMessage{
		String tableName;
		switch(modelType){
		case Src:
			tableName="SRC_TABLE_FOREIGN_REF_COL";
			break;
		case Bm:
			tableName="BM_TABLE_FOREIGN_REF_COL";
			break;
		case Dw:
			tableName="DW_TABLE_FOREIGN_REF_COL";
			break;
		case Bdsl:
			tableName="BDSL__TABLE_FOREIGN_REF_COL";
			break;
		case Dm:
			tableName="DM__TABLE_FOREIGN_REF_COL";
			break;
		default:
			throw new ErrorMessage("未处理的模型类型("+modelType+")");
		}
		return tableName;
	}
	
	/**
	 * 依据当前模型类型，返回 映射自 的模型类型
	 */
	public static Model_Type getPreModelType(Model_Type modelType) throws ErrorMessage {
		switch(modelType){
		case Bm:
			return Model_Type.Src;
		case Dw:
			return Model_Type.Bm;
		case Bdsl:
			return Model_Type.Dw;
		case Dm:
			return Model_Type.Bdsl;
		}
		throw new ErrorMessage("非期待的业务模型类型("+modelType.toString()+")");
	}


}
